#include <string.h>
#include <assert.h>

#include "COMController.h"
#include "Device_Printer.h"


HANDLE PTR_Open(int com){
	HANDLE h = COM_Open(com);
	struct COMPARA compara;
	BYTE cmd[4] = {0x1B,0x40,0x1C,0x26};
	int r;


	if (h == NULL) return NULL;
	/* Printer Property */
	compara.BaudRate = 9600;
	compara.ByteSize = 8;
	compara.Parity = 0;
	compara.StopBits = 1;
	if (COM_SetPara(h,&compara) == 0){
		COM_Close(h);
		return NULL;
	}
	r = COM_Write(h,4,cmd);
	assert(r == 4);
	return h;
}
int PTR_Print(HANDLE h,char* str){
	int size;
	if (h == NULL) return 0;
	size = sizeof(char)*(strlen(str)+1);
	return COM_Write(h,size,str);
}
int PTR_Close(HANDLE h){
	if (h == NULL) return 0;
	return COM_Close(h);
}